package com.dhcc.bpm.modules.scf.service.HomePageService.HomePageImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.modules.scf.dto.HomePageDTO.ScfMiddleInfoDTO;
import com.dhcc.bpm.modules.scf.entity.HomePage.ScfMiddleInfo;
import com.dhcc.bpm.modules.scf.mapper.HomePageMapper.ScfMiddleInfoMapper;
import com.dhcc.bpm.modules.scf.service.HomePageService.IScfMiddleInfoService;
import com.dhcc.bpm.modules.scf.util.UnitConverter;
import com.dhcc.bpm.modules.scf.vo.HomePageVO.ScfMiddleInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 中间列表服务类
 */
@Service
public class ScfMiddleInfoServiceImpl extends ServiceImpl<ScfMiddleInfoMapper, ScfMiddleInfo> implements IScfMiddleInfoService {
    @Autowired
    private UnitConverter unitConverter;
    @Override
    public IPage<ScfMiddleInfoVO> selectMiddleInfo(IPage<ScfMiddleInfoVO> page, ScfMiddleInfoDTO scfMiddleInfo) {
        List<ScfMiddleInfoVO> scfMiddleInfoVOS = baseMapper.selectMiddleInfo(page, scfMiddleInfo);
        for (ScfMiddleInfoVO scfMiddleInfoOne : scfMiddleInfoVOS) {
            // 付款重进行单位换算为万吨
            scfMiddleInfoOne.setPaymentWeight(unitConverter.convertToMetricTons(scfMiddleInfoOne.getPaymentWeight()));
            // 碳排放进行单位换算为万吨
            scfMiddleInfoOne.setCarbonEmissions(unitConverter.convertToMetricTons(scfMiddleInfoOne.getCarbonEmissions()));
        }
        return page.setRecords(scfMiddleInfoVOS);
    }
}
